package dao;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

import util.dataUtil;

import model.Crime_typeModel;

public class crime_typeDao {
	public static ArrayList<Crime_typeModel> getAll()
	{
		ArrayList<Crime_typeModel> list = new ArrayList<Crime_typeModel>();
		String sql = "Select * from Crime_type";
		try{
			PreparedStatement ps = dataUtil.getconnConnection().prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			while(rs.next())
			{
				Crime_typeModel model = new Crime_typeModel();
				model.setID(rs.getInt("id"));
				model.setName(rs.getString("name"));
				model.setLast_updated(rs.getString("last_update"));
				list.add(model);
			}
		}catch (Exception e) {
			e.printStackTrace();
		}
		
		return list;
	}
	
	public static int getid_Crime_type(String name){
		int iden = 0;
		String sql = "select * from Crime_type where name ='" +name+ "'";
		try {
			PreparedStatement ps = dataUtil.getconnConnection().prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			while(rs.next()){
				iden = rs.getInt("id");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return iden;
}
}
